package schema

import (
	"regexp"

	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
)

// EntGroup holds the schema definition for the EntGroup entity.
type EntGroup struct {
	ent.Schema
}

// Fields of the EntGroup.
func (EntGroup) Fields() []ent.Field {
	return []ent.Field{
		field.String("name").
			// Regexp validation for group name.
			Match(regexp.MustCompile("[a-zA-Z_]+$")),
	}
}

// Edges of the EntGroup.
func (EntGroup) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("users", EntUser.Type), // 定义group和user的关联关系 ：1对多
	}
}
